#!/usr/bin/python
# -*- coding: utf-8 -*-
# @Time    : 2021/6/21 21:43
# @Author  : Aaron
# @File    : conftest
# @Software: PyCharm
import pytest
from selenium import webdriver
# import sys
# sys.path.append("../..")
from calculator_pytest.codes import calculator
from calculator_pytest.tools import get_datas

calc_datas = get_datas.get_calc_data('calc.yml')

member_datas = get_datas.get_selenium_data('selenium.yml')


@pytest.fixture()
def get_calc_object():
    return calculator.Calculator()


@pytest.fixture()
def setup_teardown_func():
    print("start calc")
    yield
    print("end calc")


@pytest.fixture(scope='class')
def setup_teardown_class():
    print("up calculator")
    yield
    print("down calculator")


@pytest.fixture(
    params=calc_datas["add"]["success_data"],
    ids=calc_datas["add"]["success_ids"])
def get_add_success_datas(request):
    return request.param


@pytest.fixture(
    params=calc_datas["add"]["fail_data"],
    ids=calc_datas["add"]["fail_ids"])
def get_add_fail_datas(request):
    return request.param


@pytest.fixture(
    params=calc_datas["div"]["success_data"],
    ids=calc_datas["div"]["success_ids"])
def get_div_success_datas(request):
    return request.param


@pytest.fixture(
    params=calc_datas["div"]["fail_data"],
    ids=calc_datas["div"]["fail_ids"])
def get_div_fail_datas(request):
    return request.param


@pytest.fixture()
def setup_teardown_for_selenium():
    print("Start Selenium Driver")
    driver = webdriver.Chrome()
    driver.implicitly_wait(3)

    yield driver

    print("Down Selenium Driver")
    driver.quit()


@pytest.fixture(
    params=member_datas.get('member'))
def get_member_datas(request):
    return request.param
